package JZ;

import java.util.*;

public class jz21 {
    public static void main(String[] args) {
        int[] num = new int[]{1,5,7};
        num = reOrderArray(num);
        for (int n : num) {
            System.out.print(n + " ");
        }
    }
    public static int[] reOrderArray1 (int[] array) {
        List<Integer> num1 = new ArrayList<>();
        List<Integer> num2 = new ArrayList<>();
        for (int i = 0; i < array.length; i++) {
            if(array[i] % 2 == 1)
                num1.add(array[i]);
            else
                num2.add(array[i]);
        }
        for (int i = 0; i < num1.size(); i++) {
            array[i] = num1.get(i);
        }
        for (int i = 0; i < num2.size(); i++) {
            array[num1.size() + i] = num2.get(i);
        }
        return array;
    }

    /**
     * 插入排序思想
     * @param array
     * @return
     */
    public static int[] reOrderArray (int[] array) {
        int t = 0;
        for (int i = 0; i < array.length; i++) {
            if(array[i] % 2 == 1){
                int temp = array[i];
                int j = i - 1;
                for (; j >= t; j--) {
                    array[j + 1] = array[j];
                }
                array[t++] = temp;
            }
        }
        return array;
    }
}
